<?php
class Admin_LoginController extends Zend_Controller_Action {

    public function indexAction(){
        $form = new Application_Form_Login_Usuario();
        if( $this->_request->isPost() ){
            if( $form->isValid($this->_request->getPost()) ){
                $zendDb = Zend_Db_Table_Abstract::getDefaultAdapter();
                $authAdapter = new Zend_Auth_Adapter_DbTable(
                    $zendDb,
                    'usuario',
                    'ds_login',
                    'ds_senha'
                );

                $authAdapter->setIdentity( $form->getValue('ds_login') );
                $authAdapter->setCredential( sha1($form->getValue('ds_senha')) );
                $auth = $authAdapter->authenticate();
                if( $auth->isValid() ){
                    Zend_Loader::loadClass('Zend_Auth');
                    $auth = Zend_Auth::getInstance();
                    $auth->getStorage()->write(array(
                        'auth'  => true,
                        'acl'   => 'administrador',
                    ));

                    $this->_helper->FlashMessenger('Seja bem vindo!');
                    return $this->_helper->redirector('index','index');
                }
            }
        }
        $this->view->form = $form;
    }
    
}